package com.example.demo2;

import jdk.jfr.Frequency;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@RequestMapping("/user2")
@RestController
public class UserController2 {
    @RequestMapping("/t1")
    public String t1(String name ,Integer age){
        return "姓名："+name+"     年龄："+age;
    }
    @RequestMapping("/t2")
    public String t2(UserInfo userInfo){
        return "传递对象："+userInfo.toString();
    }

    @RequestMapping("/t3")
public String t3(@RequestParam("q") String name){
        return name;
    }

    @RequestMapping("/t4")
    public String t4(@RequestParam(value = "q",required = false) String name){
        return name;
    }
    @RequestMapping("/t5")
    public String t5(String []str){
        return Arrays.toString(str);
    }

    @RequestMapping("/t6")
    public String t6(@RequestParam List<String> str){
        return str.toString();
    }

    @RequestMapping("/t7")
    public String t7(@RequestBody List<List<String>> list){
return list.toString();
    }

@RequestMapping("/t8")
public String t8(@RequestBody UserInfo userInfo){
        return  userInfo.toString();
}

@RequestMapping("/t9/{name}/{age}")
public String t9(@PathVariable String name,@PathVariable("age") Integer userAge){
        return "name:"+name+"  age:"+userAge;
}

@RequestMapping("/t10")
public String t10(@RequestPart("file10") MultipartFile file) throws IOException {
    System.out.println(file.getOriginalFilename());
    file.transferTo(new File("D:\\图片\\代码测试图片"+file.getOriginalFilename()));
return "数据上传成功:";
}

    @RequestMapping("/m16")
    public String m16(@RequestParam("file11") MultipartFile file) throws IOException {
        System.out.println(file.getName());
        file.transferTo(new File("D:\\图片\\代码测试图片\\"+file.getOriginalFilename()));
        return "文件上传成功";
    }


    @RequestMapping("/getFile")
    public String getFile(@RequestParam MultipartFile file) throws IOException {
        System.out.println(file.getOriginalFilename());
        file.transferTo(new File("D://图片//代码测试图片"+file.getOriginalFilename()));
        return "文件获取成功";
    }


}
